package com.yanqu.road.entity.activity.horserun.cross;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_c_horse_run_user_data",desc = "小马快跑玩家数据")
public class CrossHorseRunUserData extends DataObject {
    @FieldTypeAnnotation(select = true,update = true,desc = "活动id")
    private int activityId;
    @FieldTypeAnnotation(select = true,update = true,desc = "分组id")
    private int groupId;
    @FieldTypeAnnotation(update = true,desc = "玩家id")
    private long userId;
    @FieldTypeAnnotation(desc = "商会id")
    private String unionId;
    @FieldTypeAnnotation(desc = "小马外观")
    private int horseAppearance;
    @FieldTypeAnnotation(desc = "小马装备")
    private List<Integer> equipment;
    @FieldTypeAnnotation(desc = "小马等级")
    private int level;
    @FieldTypeAnnotation(desc = "当前小马评分")
    private long nowGrade;
    @FieldTypeAnnotation(desc = "历史最高小马评分")
    private long maxGrade;
    @FieldTypeAnnotation(desc = "技能列表")
    private List<Integer> skillList;
    @FieldTypeAnnotation(desc = "基础属性点等级")
    private Map<Integer,Integer> attrLevelMap;
    @FieldTypeAnnotation(desc = "额外属性")
    private Map<Integer,Integer> extAttr;
    @FieldTypeAnnotation(desc = "总属性点")
    private Map<Integer,Integer> totalAttr;
    @FieldTypeAnnotation(desc = "报名数据 key天数 value赛场")
    private Map<Integer,Integer> signData;
    @FieldTypeAnnotation(desc = "场次结算数据",saveJson = true)
    private Map<Integer,HorseRunRacingUserResult> racingResult;
    @FieldTypeAnnotation(desc = "缓存未领取经验 商会升级的时候这里没领取会加")
    private long cacheExp;
    @FieldTypeAnnotation(desc = "上次领取计算经验的时间")
    private long lastGetExpTime;
    @FieldTypeAnnotation(desc = "未读轮次")
    private int unreadRound;
    @FieldTypeAnnotation(desc = "上次报名时间")
    private long lastSignTime;

    public int getActivityId() {
        return activityId;
    }
    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }
    }

    public int getGroupId() {
        return groupId;
    }
    public void setGroupId(int groupId) {
        if (this.groupId != groupId) {
            this.groupId = groupId;
            setOp(DataStatus.Update);
        }
    }

    public long getUserId() {
        return userId;
    }
    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setOp(DataStatus.Update);
        }
    }

    public String getUnionId() {
        return unionId;
    }
    public void setUnionId(String unionId) {
        if (unionId == null){
            return;
        }
        if (this.unionId == null || !this.unionId.equals(unionId)) {
            this.unionId = unionId;
            setOp(DataStatus.Update);
        }
    }

    public int getHorseAppearance() {
        return horseAppearance;
    }
    public void setHorseAppearance(int horseAppearance) {
        if (this.horseAppearance != horseAppearance) {
            this.horseAppearance = horseAppearance;
            setOp(DataStatus.Update);
        }
    }

    public java.util.List<java.lang.Integer> getEquipment() {
        return equipment;
    }
    public void setEquipment(java.util.List<java.lang.Integer> equipment) {
        if (null == equipment){
            return;
        }
        if (this.equipment == null || !this.equipment.equals(equipment)) {
            this.equipment = equipment;
            setOp(DataStatus.Update);
        }
    }

    public int getLevel() {
        return level;
    }
    public void setLevel(int level) {
        if (this.level != level) {
            this.level = level;
            setOp(DataStatus.Update);
        }
    }

    public long getNowGrade() {
        return nowGrade;
    }
    public void setNowGrade(long nowGrade) {
        if (this.nowGrade != nowGrade) {
            this.nowGrade = nowGrade;
            setOp(DataStatus.Update);
        }
    }

    public long getMaxGrade() {
        return maxGrade;
    }
    public void setMaxGrade(long maxGrade) {
        if (this.maxGrade != maxGrade) {
            this.maxGrade = maxGrade;
            setOp(DataStatus.Update);
        }
    }

    public java.util.List<java.lang.Integer> getSkillList() {
        return skillList;
    }
    public void setSkillList(java.util.List<java.lang.Integer> skillList) {
        if (null == skillList){
            return;
        }
        if (this.skillList == null || !this.skillList.equals(skillList)) {
            this.skillList = skillList;
            setOp(DataStatus.Update);
        }
    }

    public java.util.Map<java.lang.Integer, java.lang.Integer> getAttrLevelMap() {
        return attrLevelMap;
    }
    public void setAttrLevelMap(java.util.Map<java.lang.Integer, java.lang.Integer> attrLevelMap) {
        if (null == attrLevelMap){
            return;
        }
        if (this.attrLevelMap == null || !this.attrLevelMap.equals(attrLevelMap)) {
            this.attrLevelMap = attrLevelMap;
            setOp(DataStatus.Update);
        }
    }

    public java.util.Map<java.lang.Integer, java.lang.Integer> getTotalAttr() {
        return totalAttr;
    }
    public void setTotalAttr(java.util.Map<java.lang.Integer, java.lang.Integer> totalAttr) {
        if (null == totalAttr){
            return;
        }
        if (this.totalAttr == null || !this.totalAttr.equals(totalAttr)) {
            this.totalAttr = totalAttr;
            setOp(DataStatus.Update);
        }
    }

    public java.util.Map<java.lang.Integer, java.lang.Integer> getSignData() {
        return signData;
    }
    public void setSignData(java.util.Map<java.lang.Integer, java.lang.Integer> signData) {
        if (null == signData){
            return;
        }
        if (this.signData == null || !this.signData.equals(signData)) {
            this.signData = signData;
            setOp(DataStatus.Update);
        }
    }

    public java.util.Map<java.lang.Integer, com.yanqu.road.entity.activity.horserun.cross.HorseRunRacingUserResult> getRacingResult() {
        return racingResult;
    }
    public void setRacingResult(java.util.Map<java.lang.Integer, com.yanqu.road.entity.activity.horserun.cross.HorseRunRacingUserResult> racingResult) {
        if (null == racingResult){
            return;
        }
        if (this.racingResult == null || !this.racingResult.equals(racingResult)) {
            this.racingResult = racingResult;
            setOp(DataStatus.Update);
        }
    }

    public long getCacheExp() {
        return cacheExp;
    }
    public void setCacheExp(long cacheExp) {
        if (this.cacheExp != cacheExp) {
            this.cacheExp = cacheExp;
            setOp(DataStatus.Update);
        }
    }

    public long getLastGetExpTime() {
        return lastGetExpTime;
    }
    public void setLastGetExpTime(long lastGetExpTime) {
        if (this.lastGetExpTime != lastGetExpTime) {
            this.lastGetExpTime = lastGetExpTime;
            setOp(DataStatus.Update);
        }
    }

    public int getUnreadRound() {
        return unreadRound;
    }
    public void setUnreadRound(int unreadRound) {
        if (this.unreadRound != unreadRound) {
            this.unreadRound = unreadRound;
            setOp(DataStatus.Update);
        }
    }


    public CrossHorseRunUserData(int activityId, int groupId, long userId, String unionId) {
        this.activityId = activityId;
        this.groupId = groupId;
        this.userId = userId;
        this.unionId = unionId;
        setInsertOption();
    }

    public CrossHorseRunUserData() {
    }

    public void setAttrLevelByList(List<Integer> attrLevelList) {
        if (attrLevelMap == null){
            attrLevelMap = new ConcurrentHashMap<>();
        }

        int attrType = 1;
        for (int attrLevel : attrLevelList) {
            getAttrLevelMap().put(attrType, attrLevel);
            attrType++;
        }
        setUpdateOption();
    }

    /**
     * 用list设置map
     * @param totalAttrList
     */
    public void setTotalAttrByList(List<Integer> totalAttrList) {
        if (totalAttr == null){
            totalAttr = new ConcurrentHashMap<>();
        }
        int attrType = 1;
        for (int totalAttr : totalAttrList) {
            getTotalAttr().put(attrType, totalAttr);
            attrType++;
        }
        setUpdateOption();
    }

    /**
     * 用list设置map
     * @param extAttrList
     */
    public void setExtAttrByList(List<Integer> extAttrList) {
        if (extAttr == null){
            extAttr = new ConcurrentHashMap<>();
        }
        int attrType = 1;
        for (int totalAttr : extAttrList) {
            extAttr.put(attrType, totalAttr);
            attrType++;
        }
        setUpdateOption();
    }

    /**
     * 增加战绩
     * @param roundId
     * @param zone
     * @param rank
     * @param score
     */

    public void addHorseRunRacingUserResult(int roundId,int zone,int rank,int score,long time){
        HorseRunRacingUserResult racingUserResult = new HorseRunRacingUserResult(roundId,zone,rank,score,time);
        racingResult.put(roundId, racingUserResult);
        setUnreadRound(roundId);
        setUpdateOption();
    }

    /**
     * 获取某一轮的分数
     */
    public long getRoundScore(int roundId) {
        if (racingResult.containsKey(roundId)) {
            return racingResult.get(roundId).getScore();
        }else {
            return 0;
        }
    }

    /**
     * 获取某一轮报名的场次
     */
    public int getJoinZone(int round){
        if (signData.containsKey(round)){
            return signData.get(round);
        }
        return 0;
    }

    /**
     * 报名某一个赛区
     */
    public void sign (int roundId,int zone){
        signData.put(roundId,zone);
        setLastSignTime(System.currentTimeMillis());
        setUpdateOption();
    }

    /**
     * 获取总分
     */
    public long getTotalScore(){
        long totalScore = 0;
        for (HorseRunRacingUserResult racingUserResult : racingResult.values()) {
            totalScore += racingUserResult.getScore();
        }
        return totalScore;
    }

    public Map<Integer, Integer> getExtAttr() {
        return extAttr;
    }

    public void setExtAttr(Map<Integer, Integer> extAttr) {
        if (null == extAttr){
            return;
        }
        if (this.extAttr == null || !this.extAttr.equals(extAttr)) {
            this.extAttr = extAttr;
            setOp(DataStatus.Update);
        }
    }

    public long getLastSignTime() {
        return lastSignTime;
    }

    public void setLastSignTime(long lastSignTime) {
        if (this.lastSignTime != lastSignTime) {
            this.lastSignTime = lastSignTime;
            setOp(DataStatus.Update);
        }
    }
}
